package Practice07;

import java.io.IOException;
import java.io.RandomAccessFile;
import java.util.Scanner;

public class test8 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        RandomAccessFile raf = null;
        try {

            raf = new RandomAccessFile("E://B.txt","rw");
            int[] arr = new int[6];
            int num;
            for (int i = 1; i <= 10; i++) {
                System.out.println("请输入第"+i+"个数：");
                num = sc.nextInt();
                raf.writeInt(num);
                if (i > 4){
                    arr[i-5] = num;
                }
            }
            System.out.println("请输入要在第四个数据后插入的数据：");
            num = sc.nextInt();
            raf.seek(4*4);
            raf.writeInt(num);
            for (int n : arr){
                raf.writeInt(n);
            }
            raf.seek(0);
            while (raf.getFilePointer() < raf.length()){
                System.out.println(raf.readInt());
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        } finally {
            try {
                if (raf != null) {
                    raf.close();
                }
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
    }
}
